package com.one.piece.repository;


import com.one.piece.document.Customer;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

import java.util.List;


public interface CustomerRepository extends ElasticsearchRepository<Customer, String> {

    List<Customer> findByFirstNameOrLastName(String firstName, String lastName);

    List<Customer> findByFirstNameAndLastName(String firstName, String lastName);

    Page<Customer> findByFirstName(String firstName, Pageable pageable);

    Page<Customer> findByLastName(String lastName, Pageable pageable);

    Page<Customer> findByFirstNameOrLastName(String firstName, String lastName, Pageable pageable);

    Page<Customer> findByFirstNameAndLastName(String firstName, String lastName, Pageable pageable);

    Page<Customer> findByAgeBetween(int from, int to, Pageable pageable);

    Page<Customer> findByFirstNameLike(String firstName, Pageable pageable);

    @Query("{\"bool\" : {\"must\" : {\"term\" : {\"address\" : \"?0\"}}}}")
    Page<Customer> findByAddress(String address, Pageable pageable);


}  